<template>
  <rx-layout>
    <template v-slot:center>
      <div class="BpmTaskLinkup-center">
        <a style="color: #4d9eff;display:inline-block;padding-bottom: 16px;">{{ subject }}</a>
        <div style="margin-bottom: 0.5rem">
          <div style="margin-bottom: 0.25rem">{{i18n('communicatingPerson','沟通人')}}</div>
          <RxVueUserDialog v-model="form.toUser"></RxVueUserDialog>
        </div>
        <div>
          <div>{{i18n('opinion','意见')}}</div>
          <textarea class="BpmTaskTransferEdit-textarea" v-model="form.opinion" :placeholder="i18n('msg2','请输入意见')" />
        </div>
      </div>
    </template>
    <template v-slot:footer>
      <div class="bpm-footer">
        <div @click="closeWindow" class="bpm-footer-close">{{i18n('close','取消')}}</div>
        <div @click="submitForm" class="bpm-footer-ok">{{i18n('ok','确定')}}</div>
      </div>
    </template>
  </rx-layout>
</template>

<script>
import RxLayout from '@/components/RxLayout';
import RxVueUserDialog from '@/components/RxVueUserDialog';
import BpmtaskApi from "@/api/rxBpm/bpmTask";

export default {
  name: "BpmTaskLinkup",
  data() {
    return {
      subject: String,
      taskId: String,
      form: {
        opinion: "",
        opFiles: "",
        toUser: [],
        informTypes: []
      },
      fileList: []
    }
  },
  components: {
    RxLayout,
    RxVueUserDialog
  },
  onLoad(option) {
    let optionData = JSON.parse(option.data);
    this.subject = optionData.subject;
    this.taskId = optionData.taskId;
    this.init();
  },
  methods: {
      i18n(name,text,key){
          return this.$ti18(name,text,"bpmTaskLang.BpmInstTakeBack",key);
      },
    init() {
      this.form.taskId = this.taskId;
    },
    closeWindow() {
      uni.navigateBack({
        delta: 1
      })
    },
    submitForm(e) {
      var self_ = this;
      self_.form.msgTypes = self_.form.informTypes.join(",");
      let userIds = [];
      self_.form.toUser.forEach(res=>{
        userIds.push(res.id)
      })
      self_.form.toUserAccounts = userIds.join(',')
      delete self_.form.informTypes;
      delete self_.form.toUser;
      BpmtaskApi.submitTasklinkup(self_.form).then(res => {
        if (res.success) {
          uni.showToast({
            title: res.message, // 消息内容
            duration: 2000, // 持续时间（单位：毫秒）
            icon: 'none' // 图标类型（可选值：success/loading/none）
          });
          uni.navigateBack({
            delta: 2,//返回层数，2则上上页
          })
        }else {
          uni.showToast({
            title: res.message, // 消息内容
            duration: 2000, // 持续时间（单位：毫秒）
            icon: 'none' // 图标类型（可选值：success/loading/none）
          });
        }
      });
    }
  }
}
</script>

<style scoped>
.BpmTaskLinkup-center{
  background: white;
  border-radius: 5px;
  padding: 0.5rem;
}
.bpm-footer {
  display: flex;
  grid-gap: 10px;
}
.BpmTaskTransferEdit-textarea {
  font-size: 0.8rem;
  height: 124px;
  width: calc(100% - 1rem) !important;
  margin-top: 15px;
  border-radius: 8px;
  border: 1px solid rgba(232, 232, 232, 1);
  padding: 10px 10px 10px 10px;
}

.bpm-footer-close {
  flex: 1;
  height: 45px;
  opacity: 1;
  border-radius: 8px;
  background: rgba(255, 255, 255, 1);
  border: 1px solid rgba(232, 232, 232, 1);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 15px;
  color: rgba(0, 0, 0, 0.65);
}

.bpm-footer-ok {
  flex: 1;
  height: 45px;
  opacity: 1;
  border-radius: 8px;
  background: rgba(66, 133, 244, 1);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 15px;
  color: white;
}
</style>
